#ifndef motors_h
#define motors_h

#include "structures.h"
#include "structures.h"
#include "pwm.h"
#include "encoders.h"

#define TICS_PER_ROT 362 
#define WHEEL_RADIUS 33 // radius wheel in mm
#define PI 3.14159
#define DIR_RIGHT 4
#define DIR_LEFT 3
#define MOTOR_RIGHT 1
#define MOTOR_LEFT 0
#define MAX_VEL 100
//relationship between sample frequency and velocity
/**
 * \brief Relationship between the sample frequency and the max velocity.
 * VEL_FACT =   
 */
#define VEL_FACT 320

/**
 * \brief Updates the <code>#velocities</code> structure with the actual %velocities of the robots.
 *
 * The %velocities are measured in % units in respect to the max velocity. The max velocity is dependant on the actual voltage of the %battery.
 * The measuring follows the function:
 * \f[
 * vel[%] = sqrt{1}
 * \f]
 * \param vels The pointer to the <code>#velocities</code> structure.
 * \param sampleFreq The frequency of the call to this function, in Hz.
 */
void motors_getActualVels(velocities *vels, unsigned int sampleFreq);

/**
 * \brief Initializes all the hardware used for the motors (%encoders and pwm).
 *
 * Configures the pwm frequency for the motors and starts the odometers.
 * \param vels The frequency for pwm.
 */
void motors_init(unsigned char freq);

/**
 * \brief Sets the desired velocity for each motor.
 *
 * The velocity is defined as a percentage(%) of the max. velocity, which is dependant on the voltage of the %battery.
 * \param vel The desired velocity. It is an int betwen 0 and 100. Larger values are truncated to 100. 
 * If the parameter is negative, the motor will run backwards.
 * \param motor The selected motor. It has to be one of the following constants:
 * <ul>
 * <li>MOTOR_LEFT
 * <li>MOTOR_RIGHT
 * </ul>
 */
void motors_setVel(int vel,unsigned char motor);

#endif
